package com.plian.system.service.hr.staff.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.hr.staff.AnnualAssessment;
import com.plian.system.mapper.hr.staff.AnnualAssessmentMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.hr.staff.IAnnualAssessmentService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 年度考核结果 服务实现类
 *
 * @author gangan
 * @since 2019-09-30
 */
@Service
@AllArgsConstructor
public class AnnualAssessmentServiceImpl extends BaseServiceImpl<AnnualAssessmentMapper, AnnualAssessment> implements IAnnualAssessmentService {

	@Override
	public List<AnnualAssessment> ListByPid(Long pid) {
		return  list(new LambdaQueryWrapper<AnnualAssessment>().eq(AnnualAssessment::getIsDeleted, 0).eq(AnnualAssessment::getStaffFilesId, pid));
	}

	@Override
	public Boolean deleteLogicStaffFilesId(List<Long> ids) {
		LambdaQueryWrapper<AnnualAssessment> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(AnnualAssessment::getStaffFilesId, ids);
		List<AnnualAssessment> annualAssessments = list(queryWrapper);
		if (CollectionUtil.isNotEmpty(annualAssessments)){
			return deleteLogic(annualAssessments.stream().map(AnnualAssessment::getId).collect(Collectors.toList()));
		}
		return true;
	}
}
